package com.qcby.service.Impl;

import com.qcby.dao.TeacherDao;
import com.qcby.entity.Clazz;
import com.qcby.entity.Course;
import com.qcby.entity.Student;
import com.qcby.entity.Teacher;
import com.qcby.service.Iface.TeacherService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {
    @Resource
    private TeacherDao teacherDao;
    @Override
    public List<Teacher> findAll() {
        return teacherDao.findAll();
    }

    @Override
    public int findAllCount() {
        return teacherDao.findAllCount();
    }

    @Override
    public int findAllCountBySearch(Teacher teacher) {
        return teacherDao.findAllCountBySearch(teacher);
    }

    @Override
    public List<Teacher> findAllBySearch(Teacher teacher) {
        return teacherDao.findAllBySearch(teacher);
    }

    @Override
    public int addTeacher(Teacher teacher) {
        return teacherDao.addTeacher(teacher);
    }

    @Override
    public Teacher updateTeacherInfro(int id) {
        return teacherDao.updateTeacherInfro(id);
    }

    @Override
    public int updateTeacher(Teacher teacher) {
        return teacherDao.updateTeacher(teacher);
    }

    @Override
    public List<Clazz> loadTeacherClass(int id) {
        return teacherDao.loadTeacherClass(id);
    }

    @Override
    public List<Course> loadTeacherCourse(int id) {
        return teacherDao.loadTeacherCourse(id);
    }

    @Override
    public List<Student> findOneTeacherClass(int id) {
        return teacherDao.findOneTeacherClass(id);
    }

    @Override
    public String delete(int id) {
        if(teacherDao.classCount(id)>0){
            return "存在未解除绑定的班级信息，删除失败！";
        }
        if(teacherDao.courseCount(id)>0){
            return "存在未解除绑定的课程信息，删除失败！";
        }else{
            if(teacherDao.delete(id)>0){
                return  "删除成功！";
            }
            else{
                return  "删除失败！";
            }
        }
    }
}
